﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using mpress.net.Properties;

namespace mpress.net
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void Main_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                File.WriteAllBytes("mpress.exe", Resources.mpress);
                string[] files=(string[])e.Data.GetData(DataFormats.FileDrop);
                var options = string.Empty;
                foreach (CheckBox control in featureGroupBox.Controls)
                {
                    if(control.Checked)
                    {
                        options += " " + control.Tag;
                    }
                }
                foreach (var file in files)
                {
                    FileInfo fileInfo=new FileInfo(file);
                    if (fileInfo.Extension != ".exe") continue;
                    ProcessStartInfo ps = new ProcessStartInfo("mpress.exe")
                    {
                        CreateNoWindow = true,
                        UseShellExecute = false,
                        Arguments = string.Format("{0}{1}", file, options)
                    };
                    Process.Start(ps);
                }
                File.Delete("mpress.exe");
            }
        }

        private void Main_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Move;
        }

        private void Main_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Move;
        }
    }
}
